package com.ruoyi.dl.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dl.domain.DlWithdraw;
import com.ruoyi.dl.service.IDlWithdrawService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 提现充值记录Controller
 *
 * @author wangshouli
 * @date 2021-01-04
 */
@Controller
@RequestMapping("/dl/withdraw")
public class DlWithdrawController extends BaseController {
    private String prefix = "dl/withdraw";

    @Autowired
    private IDlWithdrawService dlWithdrawService;

    @RequiresPermissions("dl:withdraw:view")
    @GetMapping()
    public String withdraw() {
        return prefix + "/withdraw";
    }

    /**
     * 查询提现充值记录列表
     */
    @RequiresPermissions("dl:withdraw:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DlWithdraw dlWithdraw) {
        startPage();
        dlWithdraw.setOperate(1);
        List<DlWithdraw> list = dlWithdrawService.newSelectDlWithdrawList(dlWithdraw);
        return getDataTable(list);
    }

    /**
     * 导出提现充值记录列表
     */
    @RequiresPermissions("dl:withdraw:export")
    @Log(title = "提现充值记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DlWithdraw dlWithdraw) {
        dlWithdraw.setOperate(1);
        List<DlWithdraw> list = dlWithdrawService.selectDlWithdrawList(dlWithdraw);
        ExcelUtil<DlWithdraw> util = new ExcelUtil<DlWithdraw>(DlWithdraw.class);
        return util.exportExcel(list, "withdraw");
    }

    /**
     * 新增提现充值记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存提现充值记录
     */
    @RequiresPermissions("dl:withdraw:add")
    @Log(title = "提现充值记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DlWithdraw dlWithdraw) {
        dlWithdraw.setOperate(1);
        return toAjax(dlWithdrawService.insertDlWithdraw(dlWithdraw));
    }

    /**
     * 修改提现充值记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        DlWithdraw dlWithdraw = dlWithdrawService.selectDlWithdrawById(id);
        mmap.put("dlWithdraw", dlWithdraw);
        return prefix + "/edit";
    }

    /**
     * 修改保存提现充值记录
     */
    @RequiresPermissions("dl:withdraw:edit")
    @Log(title = "提现充值记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DlWithdraw dlWithdraw) {
        return toAjax(dlWithdrawService.updateDlWithdraw(dlWithdraw));
    }

    /**
     * 删除提现充值记录
     */
    @RequiresPermissions("dl:withdraw:remove")
    @Log(title = "提现充值记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(dlWithdrawService.deleteDlWithdrawByIds(ids));
    }
}
